package com.jar.exercise.多线程.AQS.Synchronized;

public class Demo2 {
    //  方案一（加volatile关键字）：  private static volatile int num = 0;
    private static int num = 0;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            while (num == 0) {
               // 方案二 加锁（因为println有synchronized）
                System.out.println();

            }
        }).start();


        Thread.sleep(3000);

        num = 1;

        System.out.println(num);

    }
}
